package com.Ele_Demo.jackiez;

import java.lang.reflect.Field;

import com.Ele_Demo.jackiez.util.LogUtil;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.XmlResourceParser;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;

public class Ele_Demo_Main extends TabActivity {
	
	private Ele_Demo_Main th;
	private TabHost tabHost;
	private TabWidget tabWidget;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		//setContentView(R.layout.tabactivity);
		setContentView(R.layout.tab_content);


		th = this;
		tabHost = (TabHost) findViewById(android.R.id.tabhost);
		
		LayoutInflater.from(this).inflate(R.layout.tab1,tabHost.getTabContentView(),true);
		
		tabWidget = tabHost.getTabWidget();
		//LogUtil.LogShow("[Tab]", "111", LogUtil.DEBUG);

		tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1",th.getResources().getDrawable(R.drawable.ic_menu_home_tab))
				.setContent(new Intent(this, Tab1.class)));
		//tabHost.addTab(tabHost.newTabSpec("tab1"));
		 
		//LogUtil.LogShow("[Tab]", "111", LogUtil.DEBUG);

		tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2",th.getResources().getDrawable(R.drawable.ic_menu_home_tab))
				 .setContent(new Intent(this, Tab2.class)));
		tabHost.setCurrentTab(0);

			Field mBottomLeftStrip;
			Field mBottomRightStrip;
			for (int i = 0; i < tabWidget.getChildCount(); i++) {
				
				if(Integer.parseInt(Build.VERSION.SDK) <= 7) {
					try {
						mBottomLeftStrip = tabWidget.getClass().getDeclaredField("mBottomLeftStrip");
						mBottomRightStrip = tabWidget.getClass().getDeclaredField("mBottomRightStrip");
						if (!mBottomLeftStrip.isAccessible()) {
							mBottomLeftStrip.setAccessible(true);
						}
						if (!mBottomRightStrip.isAccessible()){
							mBottomRightStrip.setAccessible(true);
						}
						mBottomLeftStrip.set(tabWidget, getResources().getDrawable(R.drawable.tab_one_normal));
						mBottomRightStrip.set(tabWidget, getResources().getDrawable(R.drawable.tab_one_normal));
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					tabHost.setPadding(tabHost.getPaddingLeft(), tabHost.getPaddingTop(), tabHost.getPaddingRight(), tabHost.getPaddingBottom() - 5);
				}
				View v = tabWidget.getChildAt(i);
				v.setBackgroundResource(R.drawable.tab_indicator);
				
		        XmlResourceParser xpp = getResources().getXml(R.color.tab_font_selector); 
		        try {
		        	ColorStateList csl= ColorStateList.createFromXml(getResources(),xpp);
		        	TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
		 	        tv.setTextColor(csl);
		        } catch (Exception e){

		        }
			}
			tabHost.setOnTabChangedListener(new OnTabChangeListener() {
				public void onTabChanged(String tabId) {
					
				}
			});
			
    }
	
}